//
//  CBoard.m
//  CBoard
//
//  Created by Joan Bartrina Rapesta on 9/13/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Board.h"
#import "Deck.h"
#define NUM_COMMUNITY_CARDS 5;

@interface CBoard (PrivateMethods)
-(id) initWithCBoardImage;
@end

@implementation CBoard

+(id) CBoard
{
	//return [[[self alloc] initWithCBoardImage] autorelease];
    
    return [[self alloc] autorelease];
   
}

- (void) setCBoardEnviroment
{
    m_CommunityCardsNumber = 0;
    unsigned numCommunityCards = NUM_COMMUNITY_CARDS;
    for(unsigned int cont = 0; cont < numCommunityCards; cont++)
    {
        m_CommunityCardsSprites[cont] = NULL;
    }
    
    //Definim el tapete del joc
    m_BoardSprite = [CCSprite spriteWithFile:@"tapiz.png"]; 
    m_BoardSprite.position = CGPointMake(screenSize.width / 2 , screenSize.height / 2);
    [self addChild:m_BoardSprite];
    
    //Definim la regio on posar les CommunityCards
    m_CupisinSprite = [CCSprite spriteWithFile:@"cupisin.png"]; 
    m_CupisinSprite.position = CGPointMake(screenSize.width / 2, screenSize.height / 2);
    [self addChild:m_CupisinSprite];
    
    m_uPositionIndex = 0;
}


- (void) showNewCommunityCard:(unsigned int) cardIndex 
{
    CCMoveTo* move;
    switch (m_uPositionIndex) 
    {
        case 0:
            move = [CCMoveTo actionWithDuration:TIME_SHOW_NEW_COMMUNITY_CARD 
                                       position:CGPointMake((screenSize.width / 2) -185, screenSize.height / 2)];
            break;
        case 1:
            move = [CCMoveTo actionWithDuration:TIME_SHOW_NEW_COMMUNITY_CARD 
                                       position:CGPointMake((screenSize.width / 2) -95, screenSize.height / 2)];
            break;
        case 2:
            move = [CCMoveTo actionWithDuration:TIME_SHOW_NEW_COMMUNITY_CARD 
                                       position:CGPointMake((screenSize.width / 2) +0, screenSize.height / 2)];
            break;
        case 3:
            move = [CCMoveTo actionWithDuration:TIME_SHOW_NEW_COMMUNITY_CARD
                                       position:CGPointMake((screenSize.width / 2) +95, screenSize.height / 2)];
            break;
        case 4:
            move = [CCMoveTo actionWithDuration:TIME_SHOW_NEW_COMMUNITY_CARD
                                       position:CGPointMake((screenSize.width / 2) +185, screenSize.height / 2)];
            break;
        default:
            break;
    }
        
    fileSprites = [NSString stringWithFormat:@"%i.png", cardIndex];
    m_CommunityCardsSprites[m_uPositionIndex] = [CCSprite spriteWithFile:fileSprites]; 
    [self addChild:m_CommunityCardsSprites[m_uPositionIndex]];
    m_CommunityCardsSprites[m_uPositionIndex].position = CGPointMake(0,0);
    [m_CommunityCardsSprites[m_uPositionIndex] runAction:move];
    
    m_CommunityCardsNumber++;
    m_uPositionIndex++;
    
}


- (void) removeCommunityCard:(unsigned int) cardIndex 
{
    [self removeChild:(m_CommunityCardsSprites[cardIndex]) cleanup:(true)];
}

- (void) setm_CommunityCardsValues:(unsigned int)card{
    m_CommunityCardsValues[m_uPositionIndex] = card;
}

@end

